<?php

namespace App\Kuafu\Base\Service;

use App\Kuafu\Base\Enum\BaseCodeEnum;

class PageService extends BaseService
{

    protected static $total; //总条数
    protected static $pageSize;//每页大小
    protected static $page;//页数
    protected static $currentPage;//当前页
    protected static $data = null;//数据

    public function __construct($data)
    {
        $arrData           = $data->toArray();
        self::$total       = $arrData['total'];
        self::$pageSize    = $arrData['per_page'];
        self::$data        = $arrData['data'];
        self::$currentPage = $arrData['current_page'];
        self::$page        = intval(ceil($arrData['total'] / $arrData['per_page']));
    }

    public function getDataPageList(): array
    {
        $returnArr = [
            'total'       => self::$total ?: 0,
            'pageSize'    => self::$pageSize ?: 10,
            'page'        => self::$page ?: 1,
            'currentPage' => self::$currentPage ?: 1,
            'list'        => self::$data ?: null,
        ];
        return self::returnData(BaseCodeEnum::OK, BaseCodeEnum::CODE_TEXT[BaseCodeEnum::OK], $returnArr);
    }
}
